#!/bin/sh
AppName="Internet Mobile 3G+ Bouygues Telecom"
itemtoaddA="/Applications/${AppName}.app"
itemtoadd="${AppName}.app"  

CDRomDriverName="JRDMassStorageDriver.kext"
ModemDriverName="JRDUSBModemData_MO.kext" 
modemScript="JRD_HSPA_Modem"


if [ ! -d ~/Library/LaunchAgents/ ]; then
	sudo -u $USER mkdir ~/Library/LaunchAgents
fi

#cp "${itemtoaddA}/${AppName}" ~/Library/LaunchAgents/
#new auto run way
dirAppSupport=${itemtoaddA}
dirLaunchAgents="/Users/$USER/Library/LaunchAgents"

AppTrayName="Running"
itemTray="Running"
LaunchAgentsPlistTitle="<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">"

itemLaunchAgentsPlist=`defaults read "${itemtoaddA}/Contents/Info" CFBundleIdentifier`

sudo rm -f "${dirLaunchAgents}/${itemLaunchAgentsPlist}.plist"

#echo "\n\ndirLaunchAgents=${dirLaunchAgents}\nitemLaunchAgentsPlist=${itemLaunchAgentsPlist}\nLaunchAgentsPlistTitle=${LaunchAgentsPlistTitle}\ndirAppSupport=${dirAppSupport}\nAppTrayName=${AppTrayName}\n\n\n"

defaults write "${dirLaunchAgents}/${itemLaunchAgentsPlist}" "${LaunchAgentsPlistTitle}<plist version=\"1.0\">\
<dict>\
	<key>Label</key>\
		<string>${itemLaunchAgentsPlist}</string>\
	<key>OnDemand</key>\
		<false/>\
	<key>Program</key>\
		<string>${itemtoaddA}/${AppTrayName}</string>\
	<key>RunAtLoad</key>\
		<true/>\
	<key>WorkingDirectory</key>\
		<string>${itemtoaddA}</string>\
</dict>\
</plist>"


#<key>LimitLoadToSessionType</key>\
#<string>Aqua</string>\
#<key>ProgramArguments</key>\
#<array>\
#	<string>${dirAppSupport}/${AppTrayName}</string>\
#	<string>-launchedbylogin</string>\
#</array>\

#end
sudo chown root:wheel "${dirLaunchAgents}/${itemLaunchAgentsPlist}.plist"
sudo chmod 755 "${dirLaunchAgents}/${itemLaunchAgentsPlist}.plist"

chown root "${itemtoaddA}/Contents/Resources/JRDModemService" 
chmod u+xs "${itemtoaddA}/Contents/Resources/JRDModemService"
chmod 777 "${itemtoaddA}/Running"

sudo rm /System/Library/Extensions.kextcache
sudo kextcache -k /System/Library/Extensions
sudo rm -Rf /System/Library/Caches
sudo touch /System/Library/Extensions

exit 0

